<?php
/*
易用软件
easily use soft
============================
微信：s67754457
Q  Q：1270597112
============================
快宝打印接口类 v1.0.0
============================

18625272562
yangyang520

*/
//if (!defined('Kuaidihelp_ROOT')) {
//   define('Kuaidihelp_ROOT', dirname(__FILE__) . '/');
//}

class Pays
{

	public $payinfo = array();
	public $param = array();
	
	public function pay()
	{
		
		$codepay_id  = $this->payinfo['appid'];//这里改成码支付ID
		$codepay_key = $this->payinfo['appkey']; //这是您的通讯密钥
		$this->payinfo['param'] = $this->payinfo['param']."_码支付";
		$data = array(
			"id"          => $codepay_id,//你的码支付ID
			"pay_id"      => $this->payinfo['uid'], //唯一标识 可以是用户ID,用户名,session_id(),订单ID,ip 付款后返回
			"type"        => 1,//1支付宝支付 3微信支付 2QQ钱包
			"price"       => $this->payinfo['money'],//金额100元
			"param"       => $this->payinfo['param'],//自定义参数,下单后的编号
			"notify_url"  => $this->payinfo['notify_url'],//通知地址
			"return_url"  => $this->payinfo['return_url'],//跳转地址
		); //构造需要传递的参数

		ksort($data); //重新排序$data数组
		reset($data); //内部指针指向数组中的第一个元素

		$sign = ''; //初始化需要签名的字符为空
		$urls = ''; //初始化URL参数为空

		foreach ($data AS $key => $val) { //遍历需要传递的参数
			if ($val == ''||$key == 'sign') continue; //跳过这些不参数签名
			if ($sign != '') { //后面追加&拼接URL
				$sign .= "&";
				$urls .= "&";
			}
			$sign .= "$key=$val"; //拼接为url参数形式
			$urls .= "$key=" . urlencode($val); //拼接为url参数形式并URL编码参数值
		}
		$query = $urls . '&sign=' . md5($sign .$codepay_key); //创建订单所需的参数
		$url = "http://api5.xiuxiu888.com/creat_order/?{$query}"; //支付页面
		return  $url;
	}
	
	public function notify()
	{
		//ksort($this->payinfo); //排序post参数
		//reset($this->payinfo); //内部指针指向数组中的第一个元素
		//$codepay_key="ZSzIQdN6AcwlgYtmWxdJO4tYhinIX7x4"; //这是您的密钥
		//$sign = '';//初始化
		//foreach ($this->payinfo AS $key => $val) { //遍历POST参数
		//	if ($val == '' || $key == 'sign') continue; //跳过这些不签名
		//	if ($sign) $sign .= '&'; //第一个字符串签名不加& 其他加&连接起来参数
		//	$sign .= "$key=$val"; //拼接为url参数形式
		//}
		//if (!$this->payinfo['pay_no'] || md5($sign . $codepay_key) != $this->payinfo['sign']) { //不合法的数据
		//	$this->param['title'] = "fail";
		//	$this->param['message'] = "error";
			//exit('fail');  //返回失败 继续补单
		//} else { //合法的数据
			//业务处理
		if(empty($this->payinfo['pay_no'])){
			$this->param['title'] = "fail";
			$this->param['message'] = "error";
		}else{
			//$pay_id = $this->payinfo['pay_id']; //需要充值的ID 或订单号 或用户名
			//$money = (float)$this->payinfo['money']; //实际付款金额
			//$price = (float)$this->payinfo['price']; //订单的原价
			//$param = $this->payinfo['param']; //自定义参数
			//$pay_no = $this->payinfo['pay_no']; //流水号
			$this->param['title'] = "success";
			$this->param['message'] = "ok";
		}
			//exit('success'); //返回成功 不要删除哦
		//}		
		
	}


}

?>